﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Dycox.Reporting
{
    public class ContainerElement : BlockElement
    {
        public ContainerElement()
        {

        }

        private ReportElementCollection _elements;

        public ReportElementCollection Elements
        {
            get
            {
                if (_elements == null)
                    _elements = new ReportElementCollection(this);

                return _elements;
            }
        }

        protected internal override void Render(RenderingContext context)
        {
            var style = GetRuntimeStyle();
            RenderBackground(context, style.Background);
            RenderBorders(context, style.Border);
        }

        protected virtual void RenderBackground(RenderingContext context, BackgroundStyle style)
        {
            ReportPaint.RenderBackground(context, context.CurrentContainer.Bounds, style);
        }

        protected virtual void RenderBorders(RenderingContext context, BorderStyle style)
        {
            ReportPaint.RenderBorders(context, context.CurrentContainer.Bounds, style);
        }

        protected internal override SizeF GetClientSize(RenderingContext context)
        {
            SizeF size = new SizeF();

            foreach (var elt in _elements)
            {
                RectangleF bounds = elt.GetBounds(context);

                if (bounds.Right > size.Width) size.Width = bounds.Right;
                if (bounds.Bottom > size.Height) size.Height = bounds.Bottom;
            }
            
            return size;
        }
    }
}
